<?php require RCMS_Object_QuickConfig_QuickConfig::PATH_HEADER; ?>
<?php echo $this->headLink()->appendStylesheet($this->websiteUrl . 'system/css/seotoaster.css'); ?>
<?php echo $this->headLink()->appendStylesheet($this->websiteUrl .'system/js/thickbox/thickbox.css'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/jquery/jquery.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/thickbox/thickbox.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl .'system/js/template/template.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/swfupload.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/swfupload.queue.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/fileprogress.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/handlers.js'); ?>
<?php echo $this->headScript(); ?>
<script type="text/javascript">
$(document).ready(function(){
    if(!($("#templateuploadpic").attr("disabled"))){
        initObjectSWFUpload('<?php echo $this->websiteUrl; ?>','templateuploadpic');
    }
    $("#load_list_templates").load('<?php echo $this->websiteUrl; ?>sys/backend_template/listtemlates/tname/<?php echo str_replace(' ', '-', $this->form->name->getValue());?>');
});
function initObjectSWFUpload(urlWebsite, buttonId){
    var swfu;
    var settings = {
        flash_url : ""+urlWebsite+"system/js/swfupload/swfupload.swf",
        upload_url: ""+urlWebsite+"sys/backend_swfuploader/uploadtemplate/",

        file_size_limit : "3 MB",
        file_types : "*.gif;*.png;*.jpg",
        file_types_description : "Web Image Files",
        file_upload_limit : 10,
        file_queue_limit : 0,

        custom_settings : {
            progressTarget : "UploadProgress",
            cancelButtonId : "btnCancel"
        },
        debug: false,

        // Button settings
        button_placeholder_id: buttonId,
        button_image_url: ""+urlWebsite+"system/js/swfupload/Chose_Picture.gif",
        button_width: "131",
        button_height: "25",
        button_cursor: SWFUpload.CURSOR.HAND,
        button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,

        // The event handler functions are defined in handlers.js
        file_queued_handler : fileQueued,
        file_queue_error_handler : fileQueueError,
        file_dialog_complete_handler : fileDialogComplete,
        upload_start_handler : uploadStart,
        upload_progress_handler : uploadProgress,
        upload_error_handler : uploadError,
        upload_success_handler : uploadSuccess,
        upload_complete_handler : uploadComplete,
        queue_complete_handler : queueComplete	// Queue plugin event
    };
    swfu = new SWFUpload(settings);
}
function uploadSuccess(file, serverData, responseReceived){
    var fileName = serverData;
    if(fileName.length < 15 && fileName != ''){
        var str = '<img width="182" height="222" src="<?php echo $this->websiteUrl; ?>themes/<?php echo $this->currentTheme; ?>/images/templatepreview/'+fileName+'"/>';
        document.getElementById('templateupdateimage').style.backgroundColor = '#FFFFFF';
        document.getElementById('image_name').value = fileName;
        document.getElementById('templateupdateimage').innerHTML = str;
    }
}
</script>
<div id="seotoaster" class="edittemplate">
<div class="close_window" onclick="parent.location.reload();parent.tb_remove();"></div>

<?php if($this->error): ?>
<div class="errors" onclick="this.style.display='none';"><?php echo $this->message; ?></div>
<?php echo $this->form; ?>
<input disabled="disabled" id="btnCancel" value="Cancel All Uploads" onclick="swfu.cancelQueue();" style="margin-left: 2px; font-size: 8pt; height: 29px; display:none;" type="button">
<div class="fieldset flash" style="display:none;" id="UploadProgress"></div>
<div class="admineditwhat">Edit template</div>
<div id="templateupdateimage" class="showimage">
<?php if($this->form->image_name->getValue() && $this->form->image_name->getValue()!='noimage.png'): ?>
    <img src="<?php echo $this->websiteUrl; ?>themes/default/<?php echo $this->currentTheme; ?>/templatepreview/<?php echo $this->form->image_name->getValue(); ?>" width="182" height="222" />
<?php else: ?>
    <img src="<?php echo $this->websiteUrl; ?>system/images/no_preview.png" width="182" height="222" alt="No Preview"/>
<?php endif; ?>
</div>
<div id="templatechoseother"><a href="javascript:;" onclick="$('#seotoaster').hide(); $('#load_list_templates').show();">SELECT ANOTHER <br/>TEMPLATE</a></div>
<?php else: ?>

<div class="admineditwhat">{%Edit template%} <?php if($this->form->name->getValue()): echo '(' . $this->form->name->getValue() . ')'; endif; ?></div>
<?php if($this->success): ?><div class="success" onclick="this.style.display='none';">The template is updated.</div><?php endif; ?>
<?php if(isset($this->errorElements)): ?><div class="errors" onclick="this.style.display='none';"><?php echo $this->errorElements; ?></div><?php endif; ?>
<?php  echo $this->form; ?>
<input disabled="disabled" id="btnCancel" value="Cancel All Uploads" onclick="swfu.cancelQueue();" style="margin-left: 2px; font-size: 8pt; height: 29px; display:none;" type="button">
<div class="fieldset flash" style="display:none;" id="UploadProgress"></div>
<div id="templateupdateimage" class="showimage">
<?php if($this->form->image_name->getValue() && $this->form->image_name->getValue()!='noimage.png'): ?>
    <img src="<?php echo $this->websiteUrl; ?>themes/<?php echo $this->currentTheme; ?>/images/templatepreview/<?php echo $this->form->image_name->getValue(); ?>" width="182" height="222" />
<?php else: ?>
    <img src="<?php echo $this->websiteUrl; ?>system/images/no_preview.png" width="182" height="222" alt="No Preview" />
<?php endif; ?>
</div>
<div id="templatechoseother"><a href="javascript:;" onclick="$('#seotoaster').hide(); $('#load_list_templates').show();">{%SELECT ANOTHER%} <br/>{%TEMPLATE%}</a></div>
<?php endif; ?>

</div>
<input type="hidden" id="hid-main-wsurl" name="hid-main-wsurl" value="<?php echo $this->websiteUrl; ?>" />
<div id="load_list_templates" style="display:none;" align="center"></div>
